- /* smmsize.cpp by K.Tsuru */
- /***************
- SNManager class
- ****************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- uint SNManager::effFigures = defaultEffFig; //number of effective figures specified by user
- uint SNManager::hidden = defaultHidden; //number of hidden figures
- uint SNManager::maxArraySize = defaultMaxArraySize;
- uint SNManager::maxSize[SNManager::NUMBER_TYPE];
- bool SNManager::reduceMaxSize = ENABLE;
- void SNManager::SetMaxArraySize(uint s){
- if(s <= defaultMaxArraySize) return; // do nothing
- maxArraySize = ceilpow2(s);
- SetMaxSize();
- }
- // function ID = 002
- /**************************************************************************
- enum declared in "snum.h"
- number type SNumber::type;
- lower 1st bit:integer, 2nd bit:decimal, 3rd bit:BRADIX(binary radix)
- UNKNOWN is used in StringToNumber class.
- enum NumberType { MIN_SIZE = 0, INTEGER = 1, REAL = 2, DEC_RDX = 3,
- BIN_RDX = 4, BIN_INT = 5, BIN_DEC = 6, NUMBER_TYPE = 7, UNKNOWN = 8};
- **************************************************************************/
- void SNManager::SetMaxSize(){
- maxSize[MIN_SIZE]= minArraySize;
- maxSize[DEC_INT] = maxArraySize;
- maxSize[ REAL ] = SNEffFig(REAL) +Hidden()+ 1u;
- maxSize[DEC_RDX] = (uint)DRADIX;
- maxSize[BIN_RDX] = (uint)BRADIX;
- #ifndef NDEBUG
- assert(maxSize[REAL] > minArraySize);
- #endif
- double s = (double)DFIGURES*(double)maxArraySize/log10((double)BRADIX)+1.0; // ver.2.17
- maxSize[BIN_INT] = (uint)s;
- maxSize[BIN_DEC] = SNEffFig(BIN_DEC) +Hidden()+ 1u;
- }
-
- //function ID = 003
- //number of effective figures excluding figure[0]
- uint SNManager::SNEffFig(NumberType tp){
- #ifndef NDEBUG
- assert(tp & REAL);
- #endif
- static uint fig[2] = {0 , 0};
- uint f = effFigures;//number of effective figures specified by user
-
- if(fig[0] != f){ //evaluate again
- fig[0] = f;
- //Testing in 1/3.0 = 0.33333... the justice has been confirmed.
- f = uint( (double)f*(double)DFIGURES/log10((double)BRADIX) )+1u; // ver.2.17
- if( (f+Hidden()+1) & 1 ) f++; // f+hidden+1 = even
- fig[1] = f;
- }
- return (tp == REAL) ? fig[0] : fig[1];
- }
- // function ID = 007
- /*******************************************************************************
- Provides the number of hidden figures when the number of effective figures
- "eff_fig" is given.
- b = 9, m = 512, 1/512 = 0.2% or 8
- At least two figures are necessary in the judgement of convergence in Newton's
- method.
- *********************************************************************************/
- uint SNManager::HiddenSize(uint eff_fig){
- uint b = 9, m = 1 << (b+1), h;
- if(eff_fig < m) h = 2u;
- else h = eff_fig >> b;
- return min(h, 8u);
- }
smmsize.cpp : last modifiled at 2017/03/31 20:04:22(2,664 bytes)
created at 2016/04/11 11:36:47
The creation time of this html file is 2017/10/27 10:59:17 (Fri Oct 27 10:59:17 2017).